"use strict"

var Router = require('koa-router');
var config = require('../../config/config.js');
var debug = require('debug')('router_permission');
var dao = require('../../dao/permission.js');

debug('router:' + config.http.baseUrl + '/v1/permission');
var router = new Router({
	prefix: config.http.baseUrl + '/v1/permission'
});

/*
{ 
"name":"vendor_add",
"code":123,
"description":"添加商家"
}
 */
router.post('/', function*() {
	// debug('add permission');
	// check input TODO
	var inParams = this.request.inParams;
	var result = yield dao.create(inParams);
	this.body = result;
});

// get all permissions
router.get('/list', function*() {
	var inParams = this.request.inParams || {};
	inParams.userId = this.session.userId;

	var result = yield dao.readAll(inParams);
	this.body = result;
});

module.exports = router.routes();